﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    主页
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        var timer;
        $(function () {
            //window.setInterval(onPageLoad(), 1000);
            $("#StartAjax").click(function () {
                alert("clicked");
                timer = setInterval(onPageLoad, 2000);
            });
            $("#EndAjax").click(function () {
                clearInterval(timer);
            });
        });
 
        var execCount = 0;

        function onPageLoad() {
            // alert("start Ajax");
            $("#execCount").text(++execCount);
            $.ajax({
                url: "/Home.mvc/GetCurrentData",
                type: "POST",
                dataType: "json",
                data: { ZoneId: "hangzhou_001" },
                cache: false,
                error: function (data) {
                    alert("error:" + data);
                },
                success: function (result) {
                    var str = "温度：" + result.Temperature + "湿度：" + result.Humidity + "光照：" + result.Illumination;
                    $("#QueryResult").text(str);
                }
            });
        };
    </script>
    <h2>
        <%: ViewData["Message"] %></h2>
    <p>
        若要了解有关 ASP.NET MVC 的更多信息，请访问 <a href="http://asp.net/mvc" title="ASP.NET MVC 网站">http://asp.net/mvc</a>。
    </p>
    <label id="execCount">
    </label>
    <label id="QueryResult">
        QueryResult</label>
    <button id="StartAjax">
        开始</button>
    <button id="EndAjax">
        停止</button>
</asp:Content>
